package com.yr.ryjk.pay.dao;

import java.util.List;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.ResultType;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.yr.ryjk.pay.entity.CashOut;
import com.yr.ryjk.pay.vo.CashOutDoctorVO;
import com.yr.ryjk.pay.vo.CashOutVO;

public interface CashOutMapper {
    int deleteByPrimaryKey(String id);

    int insert(CashOut record);

    int insertSelective(CashOut record);

    CashOut selectByPrimaryKey(String id);

    int updateByPrimaryKeySelective(CashOut record);

    int updateByPrimaryKey(CashOut record);

    @Select("select c.*,b.* " +
    		"from cash_out c " +
    			  "left join bank_card b " +
    			  "on c.card_id=b.card_id " +
    	    "where c.doc_id=#{2} " +
    		"order by operate_time desc "+
    	    "limit #{0},#{1}")
    @ResultMap("VoResultMap")
	List<CashOutVO> selectCashOutVoOfPageAndDoc(int start, int pageSize, String docId);

    @Select("select count(1) from cash_out where doc_id=#{0}")
    @ResultType(Integer.class)
	int selectCountAndDoc(String docId);

    @Select("select IFNULL(sum(IFNULL(coin_amount,0)),0) from cash_out where doc_id=#{0} and status=0")
    @ResultType(Integer.class)
	int selectTotalFrozenCoin(String id);

    List<CashOutDoctorVO> selectCashOut(int start, int pageSize,@Param("status")int status,@Param("realName")String name,@Param("phone")String phone);
    int selectCount(@Param("status")int status,@Param("realName")String name,@Param("phone")String phone);

    @Update("update cash_out set status=1 where find_in_set(id,#{0})")
    void updateSolveCashOutByIds(String ids);

    @Select("select c.*,d.* from cash_out c " +
    							"left join doctor d on c.doc_id=d.id " +
    		"where find_in_set(c.id,#{0})")
    @ResultMap("VoDoctorResultMap")
    List<CashOutDoctorVO> selectByIds(String ids);

    @Select("select c.*,d.*,b.* from cash_out c " +
    							"left join doctor d on c.doc_id=d.id " +
    							"left join bank_card b on c.card_id=b.card_id " +
    		"where c.id=#{id}")
    @ResultMap("VoDoctorResultMap")
    CashOutDoctorVO selectCashById(@Param("id")String id);
    
    @Select("select c.*,d.*,b.* from cash_out c " +
    							"left join doctor d on c.doc_id=d.id " +
    							"left join bank_card b on c.card_id=b.card_id " +
    		"where status=#{0}")
    @ResultMap("VoDoctorResultMap")
    List<CashOutDoctorVO> selectVoByStatus(int status);
}